package ch.fusun.baron.basic.turntask;

import java.util.Collection;
import java.util.LinkedList;

import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.player.Player;
import ch.fusun.baron.player.api.MarriageService;
import ch.fusun.baron.player.api.PlayerService;
import ch.fusun.baron.turn.TurnTask;

/**
 * Dissolves marriages that are not valid anymore
 */
public class DissolveMarriageTurnTask implements TurnTask {

    @Inject
    PlayerService playerService;
    @Inject
    MarriageService marriageService;

    /**
     * Kryo
     */
    public DissolveMarriageTurnTask() {
    }

    @Override
    public void execute() {
        Collection<Player> allMarriedMen = new LinkedList<Player>(
                marriageService.getAllMarriedMen());
        for (Player man : allMarriedMen) {
            if (man.isDead() || marriageService.getSpouse(man).isDead()) {
                marriageService.divorce(man);
            }
        }
    }
}
